package com.drop.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.drop.dao.UserInformationDao;
import com.drop.entity.User;
@Repository
public class UserInfomationDaoImpl implements UserInformationDao{
	private SessionFactory sessionFactory;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}
	@Override
	public User getUserInfo(String username) {
		// TODO Auto-generated method stub
		String hql="from User where userName=?";
		User user=(User)getSession().createQuery(hql).setParameter(0, username).uniqueResult();
		return user;
	}

	@Override
	public void updateUserInfo(User user) {
		// TODO Auto-generated method stub
		getSession().update(user);
	}

	@Override
	public User getUserById(int userid) {
		// TODO Auto-generated method stub
		return (User) getSession().get(User.class, userid);
	}

}
